package indi.pers.priv.onem;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;

/**
 * 图片工具类
 */
public class images {
    //图片,音频都是静态的
    public static BufferedImage sky; //天空图片
    public static BufferedImage bullet; //子弹图片
    //英雄机是两张图片需要数组
    public static BufferedImage[] heros; //英雄机图片数组
    //大小敌机都是1张正常图加上4张爆炸图
    public static BufferedImage[] airs; //小敌机图片数组
    public static BufferedImage[] bairs; //大敌机图片数组
    public static BufferedImage[] bees; //小蜜蜂图片数组

    static { //专门给图片初始化
        sky = redImage("background.png");
        bullet = redImage("bullet.png");
        heros = new BufferedImage[2]; //2张图片
        heros[0] = redImage("hero0.png");
        heros[1] = redImage("hero1.png");
        airs = new BufferedImage[5]; //5张图片
        bairs = new BufferedImage[5]; //5张图片
        bairs = new BufferedImage[5]; //5张图片
        airs[0] = redImage("airplane.png");
        bairs[0] = redImage("bigairplane.png");
        bees[0] = redImage("bee.png");
        for (int i = 1; i <airs.length ; i++) { //赋值4个爆炸图
            airs[i] = redImage("bom"+i+"png");
            bairs[i]=redImage("boom"+i+".png");
            bees[i]=redImage("boom"+i+".png");
            /*
            i=1 airs[1]=readImage("boom1.png");
            i=2 airs[2]=readImage("boom2.png");
            i=3 airs[3]=readImage("boom3.png");
            i=4 airs[4]=readImage("boom4.png")
             */
        }
    }

    /**
     * 读取图片fileName:图片名称
     */
    public static BufferedImage redImage(String fileName) {
        try {
            BufferedImage img = ImageIO.read(FlyingObject.class.getResource(fileName));
            return img;
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException();
        }
    }
}
